home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 0358.ZIP / DDGEN.PRG < prev    next >
Text File  |  1985-10-20  |  7KB  |  210 lines

  1. * ╔══════════════════════════════════════════════════════════════════════╗
  2. * ║                            DDGEN.PRG                                 ║
  3. * ╠══════════════════════════════════════════════════════════════════════╣
  4. * ║                                                                      ║
  5. * ║                  Author: Gene Clark  (202)252-6363                   ║
  6. * ║                     Created: October 20, 1985                        ║
  7. * ╚══════════════════════════════════════════════════════════════════════╝
  8. *
  9. *   This program reads the structure of your designated dBASEIII file and
  10. *   creates a data dictionary, containing the data file's structure and a
  11. *   description of each data field.  You supply the field description
  12. *   ("DEFINITION"), and this program supplies the rest.
  13. *
  14. SET TALK OFF
  15. SET DELIM OFF
  16. CLEAR ALL
  17. CLEAR
  18. ACTIVE=.T.
  19. DO WHILE ACTIVE
  20.   CLEAR
  21.   @ 1,10 SAY "╔══════════════════════════════════════════════════════╗"
  22.   @ 2,10 SAY "║      dBASE III Database Data Dictionary Generator    ║"
  23.   @ 3,10 SAY "╚══════════════════════════════════════════════════════╝"
  24.   @ 5,3 SAY " This program creates a dBASEIII data dictionary for a data file you"
  25.   @ 6,3 SAY " specify.  The resulting data dictionary is actually another dBASEIII"
  26.   @ 7,3 SAY " data base file with the same filename as your data file, but with an"
  27.   @ 8,3 SAY " extent of .DIC .  Once the .DIC file is created, it can be USEd like"
  28.   @ 9,3 SAY " any .DBF file as long as you USE it with the fully qualified name."
  29.   @ 10,4 SAY "You will be asked to provide the dBASEIII data base file name, a 54-"
  30.   @ 11,4 SAY "character description of the file, and a 54-character definition of"
  31.   @ 12,4 SAY "each field in the data base file."
  32.   @ 14,0
  33.   IF .NOT.FILE('DDGEN.DBF').AND..NOT.FILE('..\DDGEN.DBF')
  34.    ? "         The DDGEN.DBF Master File is Missing -- Program Aborted"
  35.    RETURN
  36.   ENDIF  
  37.   ACCE "          Please enter the database name: " TO NFILE
  38.   NFILE = UPPER(NFILE)
  39.   DFILE = NFILE+".DIC"
  40.   MFILE = NFILE+".DBF"
  41.   @ 16,0 CLEAR
  42.   * look for the .DBF - if it's not there, exit
  43.   IF .NOT. FILE('&MFILE')
  44.     @ 17,10 SAY "File &MFILE doesn't exist... EXITING."
  45.     SET DELIM ON
  46.     RETURN
  47.   ENDIF
  48.   USE &MFILE
  49.   * take a look at the file structure before starting
  50.   CLEAR
  51.   ? "THIS IS THE STRUCTURE OF YOUR DESIGNATED FILE:"
  52.   ?
  53.   DISPLAY STRUCTURE
  54.   ?
  55.   ? "====================================="
  56.   ?
  57.   ACCEPT "Press <CR> =====> " TO X
  58.   CLEAR
  59.   DEFN=SPACE(54)
  60.   * memvar DEFN allows for a 54 char. general description of the file.
  61.   @ 7,5 SAY "(This description will be saved in the 1st record of the .DIC file.)"
  62.   @ 5,0 SAY "Description, &MFILE: " GET DEFN
  63.   READ
  64.   * STRUCTURE EXTENDED creates a database containing only the names,
  65.   * length, type and decimal spaces for your file
  66.   COPY TO {} STRUCTURE EXTENDED
  67.   CLEAR
  68.   *  DDGEN.DBF is the structure of the data dictionary file.  The 
  69.   *  resulting data dictionary file will have the same file name as
  70.   *  the .DBF file, but will have a file extent of ".DIC".  The .DIC
  71.   *  file will be a dBASEIII data base file, however, and can be "USED"
  72.   *  just like any other data base file.
  73.   COPY FILE DDGEN.DBF TO &DFILE
  74.   SELE A
  75.   USE &DFILE
  76.   * Make the first record of the .DIC file be the descriptor of the entire
  77.   *  data base.
  78.   APPEND BLANK
  79.   REPLACE NUM WITH "DBF", FIELD_NAME WITH NFILE, T WITH "D", DEFINITION WITH DEFN
  80.   APPEND FROM {}
  81.   GO 2
  82.   SELE B
  83.   USE {}
  84.   COUNTER = 1
  85.   SELE A
  86.   DO WHILE .NOT.EOF()
  87.    REPLACE NUM WITH STR(COUNTER,3), T WITH B->FIELD_TYPE, LEN WITH B->FIELD_LEN
  88.    IF (B->FIELD_DEC>0)
  89.     REPLACE DEC WITH B->FIELD_DEC
  90.    ENDIF
  91.    SELE B
  92.    SKIP
  93.    SELE A
  94.    SKIP
  95.    COUNTER = COUNTER + 1
  96.   ENDDO
  97.   SELE B
  98.   USE
  99.   ERASE {}.DBF
  100.   SELE A
  101.   GO 2
  102.   CLEAR
  103.   @ 1,0 SAY "Data File: " + MFILE + "  (" + DEFN + ")"
  104.   @ 2,0 SAY "_______________________________________________________"
  105.   @ 2,55 SAY "________________________"
  106.   @ 4,0 SAY "Num Field Name T Len Dec"
  107.   @ 4,45 SAY "Field Definition"
  108.   @ 5,0 SAY "=== ========== = === ==="
  109.   @ 5,25 SAY "======================================================"
  110.   LINE = 6
  111.   COUNTER = 1
  112.   * Cycle through the list of field names to allow addition of definitions
  113.   DO WHILE .NOT. EOF()
  114.     @ LINE,0  SAY NUM
  115.     @ LINE,4  SAY FIELD_NAME
  116.     @ LINE,15 SAY T
  117.     @ LINE,17 SAY LEN
  118.     @ LINE,21 SAY DEC
  119.     @ LINE,25 GET DEFINITION
  120.     READ
  121.     CLEAR GETS
  122.     SKIP
  123.     * increment the line and field counters
  124.     LINE=LINE+1
  125.     COUNTER=COUNTER+1
  126.     * if we filled up one screen, clear for another
  127.     IF LINE=24
  128.       @ 6,0 CLEAR
  129.       LINE=6
  130.     ENDIF
  131.   ENDDO
  132.   * end of file? Print or display it.
  133.   CLEAR
  134.   WAIT "Display or Print the data dictionary?" TO P
  135.   P=UPPER(P)
  136.   @ 1,0 CLEAR
  137.   IF P = "P"
  138.    ACCEPT "Turn on the printer and press <CR> =======> " TO X
  139.    CLEAR
  140.    @ 10,20 SAY "Printing the data dictionary for "+MFILE
  141.    SET DEVICE TO PRINT
  142.   ENDIF
  143.   COUNTER=1
  144.   HEADING=.T.
  145.   GO 2
  146.   DO WHILE .NOT. EOF()
  147.     IF HEADING
  148.       @ 1,0 SAY "dBASEIII DATA BASE FILE DICTIONARY"
  149.       @ 1,57 SAY "Today's Date:"
  150.       @ 1,71 SAY DATE()
  151.       @ 3,0 SAY "Data File: " + MFILE
  152.       @ 3,40 SAY "Dictionary File: " + DFILE
  153.       @ 4,0 SAY "File Description: " + DEFN
  154.       @ 5,0 SAY "======================================================="
  155.       @ 5,55 SAY "========================"
  156.       @ 6,0 SAY "Num Field Name T Len Dec"
  157.       @ 6,45 SAY "Field Definition"
  158.       @ 7,0 SAY "=== ========== = === ==="
  159.       @ 7,25 SAY "======================================================"
  160.       LINE=8
  161.       HEADING=.F.
  162.     ENDIF
  163.     @ LINE,0  SAY NUM
  164.     @ LINE,4  SAY FIELD_NAME
  165.     @ LINE,15 SAY T
  166.     @ LINE,17 SAY LEN
  167.     @ LINE,21 SAY DEC
  168.     @ LINE,25 SAY DEFINITION
  169.     SKIP
  170.     LINE = LINE+1
  171.     COUNTER = COUNTER+1
  172.     IF (LINE>56.AND.P="P")
  173.       HEADING=.T.
  174.       EJECT
  175.     ENDIF
  176.     IF (LINE>25.AND.P<>"P")
  177.       HEADING=.T.
  178.       WAIT "               Hit any key to continue" TO X
  179.     ENDIF
  180.   ENDDO
  181.   STORE LINE+1 TO LINE
  182.   @ LINE,0 SAY "_______________________________________________________"
  183.   @ LINE,55 SAY "________________________"
  184.   IF P<>"P"
  185.       WAIT "      Last of Dictionary Lines --  Hit Any Key to Continue" TO X
  186.   ENDIF
  187.   SET DEVI TO SCREEN
  188.   * finished printing
  189.   IF P = "P"
  190.    EJECT
  191.   ENDIF
  192.   CLEAR
  193.   * check to see if there are any more files to be documented
  194.   STORE ' ' TO ANS
  195.   DO WHILE AT(ANS,'YN')=0
  196.     @ 10,0 SAY "Do you wish to document another Database? ===> " ;
  197.     GET ANS PICT '!'
  198.     READ
  199.   ENDDO
  200.   * if not, exit the loop and the program
  201.   IF ANS='N'
  202.     STORE .F. TO ACTIVE
  203.   ENDIF
  204. ENDDO
  205. @ 10,0
  206. @ 10,18 SAY "Data Dictionary(ies) Created -- Job Finished"
  207. SET DELIM ON
  208. RETURN
  209. ********* END OF FILE
  210.